﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MainClient
{
    public partial class frmLockSystem : Form
    {
        private string username;
        public frmLockSystem(string username)
        {
            InitializeComponent();
            this.username = username;
        }

        private void frmLockSystem_Load(object sender, EventArgs e)
        {

        }

        private void frmLockSystem_KeyPress(object sender, KeyPressEventArgs e)
        {

        }

        private void frmLockSystem_KeyDown(object sender, KeyEventArgs e)
        {

        }

        private void btn_Unlock_Click(object sender, EventArgs e)
        {
            // Handle unlock system operation... 
            string pwd = this.txt_pwd.Text.Trim();
            
            if (pwd == "" || pwd.Equals(""))
            {
                string strShow = "请输入密码";
                MessageBox.Show(strShow, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            // Check username and password.
            DataAccess.UserDAO loginDAO = new DataAccess.UserDAO();
            if (loginDAO.isUserExist(this.username, pwd))
            {
                this.Close();
            }
            else
            {
                if (MessageBox.Show("密码错误", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    this.txt_pwd.Text = "";
                    this.txt_pwd.Focus();
                }
            }
        }

        private void txt_pwd_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                btn_Unlock_Click(sender, e);
            }
        }
    }
}
